<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>The Ajax 03 Page</h1>
    <button onclick="doAjaxGet()">Do Ajax Get</button>
    <button onclick="doAjaxPost()">Do Ajax Post</button>
    <button onclick="doAjaxPostJson()">Do Ajax Post Json</button>
    <button onclick="doAjaxDelete()">Do Ajax Delete</button>
    <button onclick="doAjaxPut()">Do Ajax Put</button>
</div>
<span id="result"></span>
<script src="./ajax.js"></script>
<script type="text/javascript">
    function doAjaxGet(){
        const url="http://localhost:8080/doAjaxGet/beijing";
        const params="";
        ajaxGet(url,params,(result)=>{
            document.querySelector("#result").innerHTML=result;
        })
    }

    function doAjaxPost(){
        const url="http://localhost:8080/doAjaxPost";
        const params="id=102&city=shenzhen";
        ajaxPost(url,params,function(result){
            alert(result);
        })
    }

    function doAjaxPostJson(){
        const url="http://localhost:8080/doAjaxPostJson";
        const params={id:"103",city:"xiongan"};//服务端需要@RequestBodyajaxPostJSON(url,params,function(result){
        ajaxPostJSON(url,params,function(result){
            alert(result);
        })
    }

    function doAjaxPut(){
        const url="http://localhost:8080/doAjaxPut";
        const params="id=100&city=shenzhen";
        ajaxPut(url,params,function(result){
            alert(result);
        })
    }

    function doAjaxDelete(){
     const url="http://localhost:8080/doAjaxDelete";
     const params="101";
     ajaxDelete(url,params,function(result){
        alert(result);
     })
    }

</script>
</body>
</html>